import request from '@/utils/request'

// 响应结构
export interface ApiResponse<T = unknown> {
  code: number // 成功时为200，失败时为其他错误码
  message: string
  data: T
}

// 反馈类型
export interface FeedbackType {
  id?: number
  userId?: number
  username?: string
  feedbackType: string
  content: string
  contact?: string
  deviceInfo?: string
  status?: string
  createdAt?: string
  updatedAt?: string
}

// 分页查询参数
export interface FeedbackQuery {
  current: number
  pageSize: number
  status?: string
  feedbackType?: string
  keyword?: string
}

// 分页结果接口
export interface PageResult<T> {
  records: T[]
  total: number
  size: number
  current: number
  pages: number
}

// 添加反馈
export function addFeedback(data: FeedbackType) {
  return request<ApiResponse<number>>({
    url: '/feedback/add',
    method: 'post',
    data,
  })
}

// 删除反馈
export function deleteFeedback(id: number) {
  return request<ApiResponse<boolean>>({
    url: '/feedback/delete',
    method: 'post',
    params: { id },
  })
}

// 更新反馈
export function updateFeedback(data: Partial<FeedbackType>) {
  return request<ApiResponse<boolean>>({
    url: '/feedback/update',
    method: 'post',
    data,
  })
}

// 获取反馈详情
export function getFeedbackDetail(id: number) {
  return request<ApiResponse<FeedbackType>>({
    url: '/feedback/get',
    method: 'get',
    params: { id },
  })
}

// 获取当前用户的反馈列表
export function getMyFeedbackList(query: FeedbackQuery) {
  return request<ApiResponse<PageResult<FeedbackType>>>({
    url: '/feedback/list/my',
    method: 'get',
    params: query,
  })
}

// 获取所有反馈列表(管理员)
export function getAllFeedbackList(query: FeedbackQuery) {
  return request<ApiResponse<PageResult<FeedbackType>>>({
    url: '/feedback/list/all',
    method: 'get',
    params: query,
  })
}
